let util = {};

// request
util.request = function ({
	method = "GET",
    url,
    data,
    success,
    fail,
    complete
}) {
    // 请求
	if (0 != url.indexOf("http")) {
        url = util.baseUrl() + url
    }
    var header = {
        'content-type': 'application/json'
    }
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: method,
			data: data,
			header: header,
			dataType: 'json',
			success: success,
			fail: (res) => {
				let ret = new Object()
				ret.code = 0
				// ret.msg = res.errMsg
				ret.msg = '接口或网络异常'
				reject(ret)
			},
			complete: (res) => {
				if (res.statusCode === 200) { //成功
					resolve(res.data)
				} else {
					let ret = new Object()
					ret.code = 0
					ret.msg = res.errMsg
					reject(ret)
				}
			}
		})
	});
};

export default util;
